from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout
import sys

from client.connectView import ConnectView
from client.dataView import DataView
from client.clientAPI import ClientAPI


class MainWindow(QWidget):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.api = ClientAPI()
        self.InitUI()

    def InitUI(self):
        self.setWindowTitle("Client")
        vbox = QVBoxLayout()
        self.connectView = ConnectView(self.api)
        self.connectView.signal.resultSignal.connect(self.OnConnect)
        self.dataView = DataView(self.api)
        self.dataView.setEnabled(False)
        vbox.addWidget(self.connectView)
        vbox.addWidget(self.dataView)
        self.setLayout(vbox)
        self.show()

    def OnConnect(self, ret: bool):
        if ret:
            self.dataView.setEnabled(True)
            self.dataView.UpdateTags()
        else:
            print("Connect failed")


if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = MainWindow()
    sys.exit(app.exec_())
